package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.entity.AccountInfo;
import com.kbbywyclient.data.model.AccountInfoModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.BankCardManageContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Subscriber;

/**
 * Created by Jiangzx on 2017/9/15 14:55.
 */

public class BankCardManagePresenter extends BasePresenter implements BankCardManageContract.Presenter {
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil jsonUtil;

    private BankCardManageContract.View view;

    @Inject
    public BankCardManagePresenter(BankCardManageContract.View view){
        this.view=view;
    }

    @Override
    public void getUserBindCard(int salesId) {
        view.showLoadingDialog(mContext.getString(R.string.loading));
        jsonUtil.put("salesID", salesId);
        ApiServiceHelper.
                appointThreadNormal(apiService.getAccountInfo(jsonUtil.getRsaParams())).
                subscribe(new Subscriber<AccountInfoModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        view.closeLoadingDialog();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(AccountInfoModel accountInfoModel) {
                        view.closeLoadingDialog();
                        AccountInfo accountInfo=accountInfoModel.getData();
                        if(accountInfo!=null){
                            view.getDataSuccess(accountInfo);
                        }
                    }
                });
    }
}
